package ar.edu.itba.cg.score;

import com.jme.renderer.ColorRGBA;
import com.jme.scene.Text;

public class PointBoardScore {

	private Text firstText;
	private Text secondText;
	private Text totalText;
	
	private int id;
	private int first;
	private int second;
	private int total;
	private boolean complete;
	private BoardScore board;
	
	public PointBoardScore(int id, int first, BoardScore board){
		this.id=id;
		this.first= first;
		this.second=-1;
		this.total=-1;
		this.board= board;
		
		this.firstText= getText(id, 1, getStrFirst());
		this.secondText= getText(id, 2, getStrSecond());
		this.totalText= getText(id, 3, getStrTotal());
	}
	

	private Text getText(int id, int num, String str){
		Text t;
		t= Text.createDefaultTextLabel("Score " + id + num, str);
		t.setTextColor(ColorRGBA.black);
		t.setLocalScale(0.8f);
		t.setLocalTranslation(board.getPosition(id,num));
		return t;
	}
	
	public void recalcPosition(){
		firstText.setLocalTranslation(board.getPosition(id,1));
		secondText.setLocalTranslation(board.getPosition(id,2));
		totalText.setLocalTranslation(board.getPosition(id,3));
	}
	

	public int getFirst() {
		return first;
	}

	public void setFirst(int first) {
		this.first = first;
		this.firstText.getText().setLength(0);
		this.firstText.getText().append(getStrFirst());
	}

	public int getSecond() {
		return second;
	}

	public void setSecond(int second) {
		this.second = second;
		this.secondText.getText().setLength(0);
		this.secondText.getText().append(getStrSecond());
		complete= true;
	}
	
	
	
	public int getTotal() {
		return total;
	}


	public void setTotal(int total) {
		this.total = total;
		this.totalText.getText().setLength(0);
		this.totalText.getText().append(getStrTotal());
	}


	public String getStrFirst(){
		if(first<0)
			return "";
		
		if(first==10)
			return "X";
		
		return String.valueOf(first);
	}
	
	public String getStrSecond(){
		if(second<0)
			return "";
		
		if(second==10)
			return "X";
		
		if(first+second==10)
			return "/";
		
		
		return String.valueOf(second);
	}

	private String getStrTotal() {
		if(total<0)
			return "";
		
		return String.valueOf(total);
	}
	
	public boolean isComplete() {
		return complete;
	}

	public Text getFirstText() {
		return firstText;
	}

	public Text getSecondText() {
		return secondText;
	}


	public Text getTotalText() {
		return totalText;
	}


	
	
	
}
